import java.util.Vector;

import junit.framework.TestCase;
import org.imraniqbal.engine.*;
import org.imraniqbal.pacman.*;

public class PacmanTest extends TestCase {
	
	PacmanGame game;
	Map map;
	
	Pacman test1;
	

	public PacmanTest(String name) {
		super(name);		
	}

	protected void setUp() throws Exception {
		super.setUp();
		map = new Map(30,30);
		test1 = new Pacman(5,5,Direction.LEFT,3);
		game = new PacmanGame();
	}
	
	//MAPPABLE TESTS
	public void testGetSetX() {
		assertEquals(5,test1.getX()); //set to 5 originally
		test1.setX(2);
		assertEquals(2,test1.getX());
	}
	public void testGetSetY() {
		assertEquals(5,test1.getY()); //set to 5 originally
		test1.setY(2);
		assertEquals(2,test1.getY());
	}
	
	//PLAYER TESTS
	public void testSetGetDirection() {
		assertEquals(Direction.LEFT,test1.getDirection()); //default is left
		test1.setDirection(Direction.RIGHT);
		assertEquals(Direction.RIGHT,test1.getDirection());
	}
	public void testSetGetNumLives() {
		assertEquals(3,test1.getNumOflives()); //default is 3 lives
		test1.setNumOflives(5);
		assertEquals(5,test1.getNumOflives());
	}
	
	public void testUpdateLocationMovable() {
		//check 5,5 for the Player before it moves
		map.addMappable(test1);
		Vector<Mappable> temp = map.getMappable(5,5);
		assertEquals(true,temp.contains(test1));
		//attempt to move Player Left, Right, Up, Down
		assertEquals(true,test1.updateLocation(map)); //LEFT
		temp = map.getMappable(4,5);
		assertEquals(true,temp.contains(test1));
		
		test1.setDirection(Direction.RIGHT); 
		assertEquals(true,test1.updateLocation(map)); //RIGHT
		temp = map.getMappable(5,5);
		assertEquals(true,temp.contains(test1));
		
		test1.setDirection(Direction.UP); 
		assertEquals(true,test1.updateLocation(map)); //UP
		temp = map.getMappable(5,4);
		assertEquals(true,temp.contains(test1));
		
		test1.setDirection(Direction.DOWN); 
		assertEquals(true,test1.updateLocation(map)); //DOWN
		temp = map.getMappable(5,5);
		assertEquals(true,temp.contains(test1));
	}
	public void testUpdateLocationCantMove() {
		//check 5,5 for the Player before it moves
		map.addMappable(test1);
		Vector<Mappable> temp = map.getMappable(5,5);
		assertEquals(true,temp.contains(test1));
		//add Walls around player, now it will never move
		map.addWall(4,5);
		map.addWall(6,5);
		map.addWall(5,4);
		map.addWall(5,6);
		//attempt to move Player Left, Right, Up, Down
		assertEquals(false,test1.updateLocation(map)); //LEFT
		temp = map.getMappable(5,5);
		assertEquals(true,temp.contains(test1));
		
		test1.setDirection(Direction.RIGHT); 
		assertEquals(false,test1.updateLocation(map)); //RIGHT
		temp = map.getMappable(5,5);
		assertEquals(true,temp.contains(test1));
		
		test1.setDirection(Direction.UP); 
		assertEquals(false,test1.updateLocation(map)); //UP
		temp = map.getMappable(5,5);
		assertEquals(true,temp.contains(test1));
		
		test1.setDirection(Direction.DOWN); 
		assertEquals(false,test1.updateLocation(map)); //DOWN
		temp = map.getMappable(5,5);
		assertEquals(true,temp.contains(test1));
	}
	
	//PACMAN TESTS
	public void testConstructor() {
		Pacman testConstructor = new Pacman(5,5);
		assertEquals(5, testConstructor.getX());
		assertEquals(5, testConstructor.getY());
		assertEquals(Direction.LEFT, testConstructor.getDirection());
		assertEquals(1, testConstructor.getNumOflives());
		assertEquals(PacmanState.NORMAL, testConstructor.getState());
		
		testConstructor = new Pacman(5, 5, Direction.RIGHT, 3);
		assertEquals(5, testConstructor.getX());
		assertEquals(5, testConstructor.getY());
		assertEquals(Direction.RIGHT, testConstructor.getDirection());
		assertEquals(3, testConstructor.getNumOflives());
		assertEquals(PacmanState.NORMAL, testConstructor.getState());
	}
	
	public void testSpawnDie() {
		test1.spawn(map); //3 lives left
		assertEquals(true,map.getMappable(9,9).contains(test1)); //assert that test1 is on the map
		assertEquals(3,test1.getNumOflives());
		test1.die(map); //2 lives left
		assertEquals(true,map.getMappable(9,9).contains(test1)); //assert that test1 is on the map
		assertEquals(2,test1.getNumOflives());
		test1.die(map); //1 life left
		assertEquals(true,map.getMappable(9,9).contains(test1)); //assert that test1 is on the map
		assertEquals(1,test1.getNumOflives());
		test1.die(map); //DEAD
		assertEquals(null,map.getMappable(9,9)); //assert that test1 is NOT on the map
		assertEquals(0,test1.getNumOflives());
	}
	
	public void testOnEventGhostnoBeast() {
		//steps on Ghost, nonBeastMode
		Map tempMap = game.getMap();
		tempMap.addMappable(test1);
		Ghost tempGhost = new Ghost(5,5,2);
		tempMap.addMappable(tempGhost);
		assertEquals(true, tempMap.getMappable(5,5).contains(test1));
		test1.onEvent(new GameEvent(game));
		assertEquals(false, tempMap.getMappable(5,5).contains(test1)); //pacman dead
	}
	public void testOnEventGhostonBeast() {
		//steps on Ghost, ON Beastmode
		Map tempMap = game.getMap();
		tempMap.addMappable(test1);
		Ghost tempGhost = new Ghost(5,5,2);
		tempMap.addMappable(tempGhost);
		test1.setState(PacmanState.BEASTMODE);
		assertEquals(true, tempMap.getMappable(5,5).contains(test1));
		test1.onEvent(new GameEvent(game));
		assertEquals(true, tempMap.getMappable(5,5).contains(test1)); //pacman alive
	}
	public void testOnEventBigPill() {
		//steps on big Pill
		Map tempMap = game.getMap();
		tempMap.addMappable(test1);
		BigPill tempPill = new BigPill(5,5);
		tempMap.addMappable(tempPill);
		assertEquals(true, tempMap.getMappable(5,5).contains(test1));
		assertEquals(PacmanState.NORMAL, test1.getState());
		test1.onEvent(new GameEvent(game));
		assertEquals(false, tempMap.getMappable(5,5).contains(tempPill));
		assertEquals(PacmanState.BEASTMODE, test1.getState());
	}
	public void testOnEventLittlePill() {
		//steps on little Pill
		Map tempMap = game.getMap();
		tempMap.addMappable(test1);
		LittlePill tempPill = new LittlePill(5,5);
		tempMap.addMappable(tempPill);
		assertEquals(true, tempMap.getMappable(5,5).contains(test1));
		test1.onEvent(new GameEvent(game));
		assertEquals(false, tempMap.getMappable(5,5).contains(tempPill));
		assertEquals(20,game.getScore());
		
	}
	
	
	
	
	
	
	
}